package main

import (
	"github.com/hyperledger/fabric/core/chaincode/shim"
	pb "github.com/hyperledger/fabric/protos/peer"
	"fmt"
)

var logger = shim.NewLogger("ShimLogger")

type BaseChaincode struct {
}

func (t *BaseChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
	logger.Info("ChainCode Test init...............")
	return shim.Success([]byte("init success"))
}

func (t *BaseChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
	var result []byte
	//var err error
	function, _ := stub.GetFunctionAndParameters()
	logger.Info("Invoke mehtod : " + function)
	if function == "add" {
		stub.PutState("1", []byte("add"))
	} else if function == "query" {
		result, _ = stub.GetState("1")
		return shim.Success(result)
	}
	return shim.Success([]byte("no fcn"))
}

func main() {
	err := shim.Start(new(BaseChaincode))
	if err != nil {
		fmt.Printf("Error starting the blacklist chaincode: %s", err)
	}
}

